<!-- user表单弹窗 -->
<form id="user-form" lay-filter="user-form" class="layui-form model-form">
    <input name="csrftoken" type="hidden" value="${csrftoken!}">
    <div class="layui-form-item">
        <label class="layui-form-label">AppId</label>
        <div class="layui-input-block">
        	<select name="appId" id="baidu-face-lib-apps" lay-verify="required"></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">人脸库名称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入人脸库名称" type="text" class="layui-input" lay-verify="required" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="user-form-submit" lay-submit>保存</button>
    </div>
</form>

<!-- Apps -->
<script type="text/html" id="baiduFaceLib-tpl-select-options">
	<option value="">请选择一个应用</option>
	{{#  layui.each(d.list, function(index, item){ }}
    	<option value="{{ item.value }}">{{ item.name }}</option>
  	{{#  }); }}
</script>
<script>
    layui.use(['layer', 'laytpl', 'admin', 'form'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var laytpl = layui.laytpl;
        
        layer.load(2);
        admin.req('${rc.contextPath}/baiduApp/alls', {}, function (data) {
            layer.closeAll('loading');
            if (data.code == 200) {
            	
                laytpl($('#baiduFaceLib-tpl-select-options').html()).render({
                	list: data.data
                }, function(html){
                	$("#baidu-face-lib-apps").html(html)
                    form.render('select');
               	});
            	
            } else {
                layer.msg(data.message, {icon: 2});
            }
        }, "POST");
        
        // 表单提交事件
        form.on('submit(user-form-submit)', function (data) {
            layer.load(2);
            admin.req('${rc.contextPath}/baiduFaceLib/save', data.field, function (data) {
                layer.closeAll('loading');
                if (data.code == 200) {
                    layer.msg(data.message, {icon: 1});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.message, {icon: 2});
                }
            }, "POST");
            return false;
        });
    });
</script>